<?php
class TestDimens extends CActiveRecord {
	
	public static function model($className = __CLASS__) {
		return parent::model($className);
	}

	public function tableName() {
		return strtolower('PsyTestDimensionality');
	}
	
    public function relations() {
        return array(
            'topic' => array(self::BELONGS_TO, 'TestTopics', 'topicId',
                'joinType'=> 'RIGHT JOIN',
            ),
		);
    }

	public function rules() {
		return array(
			array('topicId, sku, dimensDescr', 'required'),
			array('sku', 'match', 'pattern' => '/^[\d\w]+$/'),
//			array('sku', 'unique', 'attributes' => array('sku', 'topicId'))
		);
	}
	
	public function attributeLabels() {
		return array(
			'sku' => '标识',
			'dimensDescr' => '说明'
		);
	}

    public function getReplacer() {
        return '$'.$this->sku;
    }
	
	public function afterDelete() {
		TestAnswerMark::model()->deleteAll('dimensId = '.$this->dimensId);
	}
}
